pv-grub: Fix for incorrect dom->p2m_host[] list initialization
authorDaniel Kiper <dkiper@net-space.pl>
Wed, 27 Apr 2011 12:29:14 +0000 (13:29 +0100)
committerDaniel Kiper <dkiper@net-space.pl>
Wed, 27 Apr 2011 12:29:14 +0000 (13:29 +0100)
commit9841d94c95bf97c3cd3c9ca14170fc88dc3b8305
tree03c1c81b2514a0ce2ef4ffab27ba62bfa7da5d5e
parentcd1eb9fd2de29745130481209cd97d1258dc9b9c
pv-grub: Fix for incorrect dom->p2m_host[] list initialization

Introduction of Linux Kernel git commit
ceefccc93932b920a8ec6f35f596db05202a12fe (x86: default
CONFIG_PHYSICAL_START and CONFIG_PHYSICAL_ALIGN to 16 MB) revealed
deeply hidden bug in pv-grub. During kernel load stage dom->p2m_host[]
list has been incorrectly initialized.

At the beginning of kernel load stage dom->p2m_host[] list is
populated with current PFN->MFN layout. Later during memory allocation
(memory is allocated page by page in kexec_allocate()) page order is
changed to establish linear layout in new domain. It is done by
exchanging subsequent MFNs with newly allocated MFNs. dom->p2m_host[]
list is indexed by currently requested PFN (it is incremented from 0)
and PFN of newly allocated paged. If PFN of newly allocated page is
less than currently requested PFN then earlier allocated MFN is
overwritten which leads to domain crash later. This patch corrects
that issue. If PFN of newly allocated page is less then currently
requested PFN then relevant PFN/MFN pair is properly calculated and
usual exchange occurs later.

Signed-off-by: Daniel Kiper <dkiper@net-space.pl>
Reviewed-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
stubdom/grub/kexec.c